home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
comm
/
term
/
term34Source.lha
/
PrintPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
11KB
|
406 lines
/*
** PrintPanel.c
**
** Control panel to set options for phonebook printing
**
** Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
enum { GAD_FILE, GAD_SELECT_FILE, GAD_PLAIN, GAD_INCLUDE_SERIAL, GAD_INCLUDE_MODEM, GAD_INCLUDE_SCREEN,
GAD_INCLUDE_TERMINAL,GAD_INCLUDE_USER, GAD_INCLUDE_COMMENT, GAD_USE, GAD_CANCEL };
STATIC UBYTE OutputFile[MAX_FILENAME_LENGTH] = "PRT:";
STATIC ULONG Flags = PRINT_SERIAL | PRINT_MODEM | PRINT_SCREEN | PRINT_TERMINAL | PRINT_USERNAME | PRINT_COMMENT;
STATIC BYTE Plain = FALSE;
STATIC struct Gadget *
CreateAllGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD Counter = 0;
SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
memset(&NewGadget,0,sizeof(struct NewGadget));
if(Gadget = CreateContext(GadgetList))
{
SZ_AddLeftOffset(SZ_LeftOffsetDelta(MSG_PRINTPANEL_OUTPUT_FILE_OR_DEVICE_GAD,MSG_PRINTPANEL_INCLUDE_COMMENT_GAD));
SZ_SetWidth(SZ_Width(FILE_KIND,NULL,30,NULL));
NewGadget . ng_GadgetText = LocaleString(MSG_PRINTPANEL_OUTPUT_FILE_OR_DEVICE_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_LeaveFolder, TRUE,
GTST_String, OutputFile,
GTST_MaxChars, 255,
TAG_DONE);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(FILE_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_PlaceLeft, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_PRINTPANEL_PLAIN_TEXT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTCB_Checked, Plain,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_PRINTPANEL_INCLUDE_SERIAL_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignExtra, TRUE,
GTCB_Checked, Flags & PRINT_SERIAL,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_PRINTPANEL_INCLUDE_MODEM_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTCB_Checked, Flags & PRINT_MODEM,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_PRINTPANEL_INCLUDE_SCREEN_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTCB_Checked, Flags & PRINT_SCREEN,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_PRINTPANEL_INCLUDE_TERMINAL_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTCB_Checked, Flags & PRINT_TERMINAL,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_PRINTPANEL_INCLUDE_USER_NAME_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTCB_Checked, Flags & PRINT_USERNAME,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_PRINTPANEL_INCLUDE_COMMENT_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTCB_Checked, Flags & PRINT_COMMENT,
TAG_DONE);
SZ_ResetMaxWidth();
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
SZ_SetWidth(SZ_ResetMaxWidth());
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_USE_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignExtra, TRUE,
SZ_AlignLeft, TRUE,
SZ_AlignBottom, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_CANCEL_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignRight, TRUE,
TAG_DONE);
}
return(Gadget);
}
VOID
PrintPanel(struct Window *Window,struct List *PhoneList,LONG Count)
{
struct Window *PanelWindow;
struct Gadget *GadgetList = NULL;
struct Gadget *GadgetArray[GAD_CANCEL + 1];
BYTE Result = FALSE;
if(CreateAllGadgets(GadgetArray,&GadgetList))
{
if(PanelWindow = OpenWindowTags(NULL,
WA_Left, GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
WA_Top, GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight()) / 2,
WA_Width, SZ_GetWindowWidth(),
WA_Height, SZ_GetWindowHeight(),
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_CustomScreen,Window -> WScreen,
WA_IDCMP, IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_CLOSEWINDOW | BUTTONIDCMP | CHECKBOXIDCMP | STRINGIDCMP,
WA_Title, LocaleString(MSG_PRINTPANEL_OUTPUT_OPTIONS_TXT),
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG IClass,Code;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
UBYTE DummyBuffer[MAX_FILENAME_LENGTH],
*DummyChar;
struct FileRequester *FileRequest;
STRPTR Name;
GuideContext(CONTEXT_PRINT);
PushWindow(PanelWindow);
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
ActiveGadget = NULL;
ClrSignal(SIG_BREAK);
while(!Terminated)
{
if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
break;
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
IClass = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
KeySelect(GadgetArray,GAD_CANCEL,Code,PanelWindow,&Gadget,&IClass,&Code);
if(IClass == IDCMP_GADGETDOWN)
{
if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
ActiveGadget = Gadget;
}
if(IClass == IDCMP_ACTIVEWINDOW && ActiveGadget)
ActivateGadget(ActiveGadget,PanelWindow,NULL);
if(IClass == IDCMP_CLOSEWINDOW)
Terminated = TRUE;
if(IClass == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_SELECT_FILE:
BlockWindow(PanelWindow);
strcpy(DummyBuffer,SZ_GetString(GadgetArray[GAD_FILE]));
if(DummyBuffer[0])
{
if(FilePart(DummyBuffer) == DummyBuffer)
DummyBuffer[0] = 0;
else
{
DummyChar = PathPart(DummyBuffer);
*DummyChar = 0;
}
DummyChar = FilePart(SZ_GetString(GadgetArray[GAD_FILE]));
}
else
DummyChar = "";
if(!DummyChar[0])
{
DummyBuffer[0] = 0;
DummyChar = LocaleString(MSG_PRINTPANEL_FILENAME_TXT);
}
if(FileRequest = GetFile(LocaleString(MSG_PRINTPANEL_SELECT_OUTPUT_FILE_TXT),DummyBuffer,DummyChar,DummyBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
{
GT_SetGadgetAttrs(GadgetArray[GAD_FILE],PanelWindow,NULL,
GTST_String,DummyBuffer,
TAG_DONE);
FreeAslRequest(FileRequest);
}
ReleaseWindow(PanelWindow);
break;
case GAD_USE:
Terminated = TRUE;
Plain = SZ_GetChecked(GadgetArray[GAD_PLAIN]);
Flags = NULL;
if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_SERIAL]))
Flags |= PRINT_SERIAL;
if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_MODEM]))
Flags |= PRINT_MODEM;
if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_SCREEN]))
Flags |= PRINT_SCREEN;
if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_TERMINAL]))
Flags |= PRINT_TERMINAL;
if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_USER]))
Flags |= PRINT_USERNAME;
if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_COMMENT]))
Flags |= PRINT_COMMENT;
Name = SZ_GetString(GadgetArray[GAD_FILE]);
if(Name[0])
{
strcpy(OutputFile,Name);
Result = TRUE;
}
break;
case GAD_CANCEL:
Terminated = TRUE;
break;
}
}
ActiveGadget = NULL;
}
}
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
}
}
if(Result)
{
LONG Error = 0;
BPTR File;
if(File = Open(OutputFile,MODE_NEWFILE))
{
struct Window *ReqWindow;
struct EasyStruct Easy;
Easy . es_StructSize = sizeof(struct EasyStruct);
Easy . es_Flags = NULL;
Easy . es_Title = (UBYTE *)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
Easy . es_GadgetFormat = (UBYTE *)LocaleString(MSG_PRINT_STOP_TXT);
Easy . es_TextFormat = (UBYTE *)LocaleString(MSG_PRINT_PRINTING_PHONEBOOK_TXT);
if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
{
struct PhoneNode *TempNode;
BYTE Continue = TRUE;
if(Count > 0)
{
for(TempNode = (struct PhoneNode *)PhoneList -> lh_Head ; Continue && TempNode -> VanillaNode . ln_Succ ; TempNode = (struct PhoneNode *)TempNode -> VanillaNode . ln_Succ)
{
if(TempNode -> Entry -> Count >= 0)
Continue = PrintEntry(File,ReqWindow,Plain,&Error,TempNode -> Entry,Flags);
}
}
else
{
for(TempNode = (struct PhoneNode *)PhoneList -> lh_Head ; Continue && TempNode -> VanillaNode . ln_Succ ; TempNode = (struct PhoneNode *)TempNode -> VanillaNode . ln_Succ)
Continue = PrintEntry(File,ReqWindow,Plain,&Error,TempNode -> Entry,Flags);
}
FreeSysRequest(ReqWindow);
}
Close(File);
if(PathPart(OutputFile) != OutputFile)
{
AddProtection(OutputFile,FIBF_EXECUTE);
if(Config -> MiscConfig -> CreateIcons)
AddIcon(OutputFile,FILETYPE_TEXT,TRUE);
}
}
else
Error = IoErr();
if(Error)
{
STRPTR ErrorString;
if(Fault(Error,"",SharedBuffer,MAX_FILENAME_LENGTH))
ErrorString = SharedBuffer;
else
ErrorString = "???";
MyEasyRequest(Window,LocaleString(MSG_PRINT_ERROR_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error,ErrorString);
}
}
ActiveGadget = NULL;
FreeGadgets(GadgetList);
}